package com.tjbklx1.thread.new5.demo03.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class FutureTest {
	
	public static void main(String[] args) {
		test1();
	}
	
	private static void test1() {
		ExecutorService threadPool =Executors.newSingleThreadExecutor();
		Future<String> future=threadPool.submit(new Callable<String>(){
			public String call() throws Exception {
				Thread.sleep(2000);
				return "Hello";
			}
		});
		System.out.println("等待结果");
		try {
			System.out.println("拿到结果"+ future.get());
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}
